import React, { Component } from 'react'
import { connect } from 'dva';
import FormList from '../components/FormItem';
import { KEYS_EDIT } from '../enum';

interface Props {
  dispatch?: Function,
  data: {
    id: string;
    cameraBrand: string;
    cameraProduct: string;
    cameraBrandName: string;
    cameraProductName: string;
    cameraSn: string;
    isCamera: Boolean | number;
    name: string;
    location: string;
    manager: string;
    mobile: string;
    telephone: string;
    builds: Array<{ name: string, id: string, fireRoomId?: string }>;
    cameraAddr: string;
    cameraProtocol: string;
  },
  match?: {
    params: {
      id: string
    }
  },
}


@connect(({ fireroom }) => ({
  data: fireroom.editDetails
}))
class Update extends Component<Props, any> {

  componentDidMount() {
    const { dispatch, match } = this.props;
    const { params } = match;

    dispatch({
      type: 'fireroom/queryEditInfoById',
      payload: {
        id: params.id,
        keys: KEYS_EDIT
      }
    })
  }

  render() {
    return (
      <section style={{ background: '#fff' }}>
        <FormList data={this.props.data} key={Date.now()}/>
      </section>
    );
  }
}

export default Update;